﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Diagnostics;
using System.Reflection;

namespace Copy4Backup
{
	/// <summary>
	/// Logger.
	/// </summary>
	public sealed class Logger
	{
		/// <summary>
		/// Suppress default ctor.
		/// </summary>
		private Logger()
		{
		}
		/// <summary>
		/// Logss the message.
		/// </summary>
		/// <param name="message">The message to log.</param>
		[Conditional("DEBUG")]
		public static void Log(string message)
		{
			string fileName = GetLogFileName();

			using (StreamWriter sw = new StreamWriter(fileName, true))
			{
				StackTrace st = new StackTrace(true);
				StackFrame sf = st.GetFrame(1);
				sw.WriteLine(String.Format("{0} {1}:{2} {3}", sf.GetFileName(), sf.GetMethod().Name.ToString(), sf.GetFileLineNumber().ToString(), message.ToString()));
			}
		}

		/// <summary>
		/// Gets the log file name.
		/// </summary>
		/// <returns></returns>
		private static string GetLogFileName()
		{
			string fileName;

			fileName = System.Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
			fileName += "\\" + Assembly.GetExecutingAssembly().GetName().Name;
			fileName += "\\log.txt";
			return fileName;
		}
	}
}
